package com.then.architecture.data.request;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 42524 on 2018/1/24.
 */

public abstract class BaseReq implements Bean2Map {

    @Override
    public Map<String, String> toMap() {
            Map<String, String> map = new HashMap<>();
            Field[] declaredFields = getClass().getDeclaredFields();
            for (Field field : declaredFields) {
                field.setAccessible(true);
                try {
                    if (field.get(this) == null) {
                        map.put(field.getName(), "");
                    } else {
                        map.put(field.getName(), field.get(this).toString());
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            return map;
    }
}
